/* Copyright (c) 2012 Jeremy Cartwright. All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.
   * Neither the name of Jeremy Cartwright nor the names of its
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//  Author: Jeremy Cartwright
// Contact: jeremy@tcjc8.com
// Created: Mon Nov 12 22:31:14 CST 2012
//
/* staffinagle is a scheduling tool.
 * manage multiple business units with multiple staff.
 * report results by business unit or staff.
 * email schedules to staff.
 * tally total scheduled hours by staff, business unit.
 * color coded, flag if shift is not covered.
 */
//
// Package Name
package staffinagle

// Import
import (
    //"appengine/datastore"
    //"fmt"
    "net/http"
    "html/template"
    "appengine"
    "appengine/user"
)

// Structs
type Staff struct {
    Name string
    Email string
    Phone string
    HomeUnit string
    ShiftGood []int64
    ShiftBad []int64
}

type Unit struct {
    Name string
    Phone string
    Address string
    HoursOpen []int64
}

// Functions

// let's get this thing started
func init() {
    http.HandleFunc("/", dashboard)
    //http.HandleFunc("/README", README)
    //http.HandleFunc("/staff", staff)
    //http.HandleFunc("/lob", lob)
    //http.HandleFunc("/schedule", schedule)
    //http.HandleFunc("/payroll", payroll)
    //http.HandleFunc("/report", report)
}

// write info to page
func dashboard(w http.ResponseWriter, r *http.Request) {

    type dash struct {
        EMP int
        BU int
    }

    c := appengine.NewContext(r)
    u := user.Current(c)
    if u == nil {
        url, err := user.LoginURL(c, r.URL.String())
        if err != nil {
            http.Error(w, err.Error(), http.StatusInternalServerError)
            return
        }
        w.Header().Set("Location", url)
        w.WriteHeader(http.StatusFound)
        return
    }
    d := dash{EMP: 8, BU: 3}
    t := template.Must(template.New("dashboard").ParseFiles("app/tmpl/dashboard.html"))
    t.ExecuteTemplate(w, "dashboard.html", d)
}
